package leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * Is Unique: Implement an algorithm to determine if a string has all unique characters.
 * (input only including a-z)
 */
public class Main {
    public static void main(String[] args) {
        String s = "abbc";
        String s1 = "abc";
        String s2 = "";


        System.out.println("是否唯一" + new Main().isUnique(s));
        System.out.println("是否唯一" + new Main().isUnique(s1));
        System.out.println("是否唯一" + new Main().isUnique(s2));
    }

    public Boolean isUnique(String s) {
        if (s == null || s.length() == 0) {
            return true;
        }
        char[] arr = s.toCharArray();
        Set<Character> set = new HashSet<>();
        // abbc
        for (char c : arr) {
            if (!set.add(c)) {
                return false;
            }
        }
        return true;
    }
}
